// console.log(process.env);
const path = require("path");
const resolve = (dir) => {
  return path.join(__dirname, dir);
};
module.exports = {
  lintOnSave: false,
  publicPath: "./", //解决打包上线时，文件路径变为绝对路径，显示空白
  assetsDir: "static",
  outputDir: "h5_001",
  productionSourceMap: false,
  devServer: {
    overlay: {
      warnings: false,
      errors: false
    }
  },

  chainWebpack: (config) => {
    config.output.filename("static/js/[name].[hash].js").end();
    config.devServer.disableHostCheck(true);
    //修改webpack打包的入口文件。需要在根目录建两个对应入口js文件
    config
      .entry("app")
      .clear()
      .add(`./src/pages/main.js`);
  },
  css: {
    extract: process.env.NODE_ENV === "production",
    sourceMap: false,
    requireModuleExtension: true,
    loaderOptions: {
      less: {
        // 若使用 less-loader@5，请移除 lessOptions 这一级，直接配置选项。
        lessOptions: {
          modifyVars: {
            // 或者可以通过 less 文件覆盖（文件路径为绝对路径）
            // hack: `true; @import "~@/assets/style/coverVant.less";`,
          },
        },
      },
      postcss: {
        plugins: [
          require("postcss-pxtorem")({
            //配置项，详见官方文档
            rootValue: 36,
            propList: ["*"],
            minPixelValue: 12,
            unitPrecision: 6,
          }), // 换算的基数
        ],
      },
    },
  },
  pluginOptions: {
    "style-resources-loader": {
      preProcessor: "less",
      patterns: [resolve("./src/assets/style/common.less")],
    },
  },
  // eslint-disable-next-line prettier/prettier
};